package com.daily.pump.widget.zxing;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.daily.pump.R;

/**
 * Desc:二维码扫描-扫描横线
 * <p>
 * Author: [李豫]
 * Date: 2019-01-02
 * Copyright: Copyright (c) 2010-2018
 * Company: @咪咕动漫
 * Updater:
 * Update Time:
 * Update Comments:
 */
public class LineView extends View {

    private Paint paint;//声明画笔
    private int line_color;
    private String line_colors;
    private Shader mShader;

    public LineView(Context context) {
        super(context);
    }

    public LineView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        line_color = getResources().getColor(R.color.zxing_color_scan_corner);
        line_colors = Integer.toHexString(line_color);

        paint = new Paint();//创建一个画笔

        paint.setStyle(Paint.Style.FILL);//设置非填充
        paint.setStrokeWidth(15);//笔宽5像素
        // paint.setColor(line_color);//设置为红笔
        paint.setAntiAlias(true);//锯齿不显示
    }

    public void setLinecolor(int color) {
        line_color = color;
        line_colors = Integer.toHexString(line_color);
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        line_colors = line_colors.substring(line_colors.length() - 6, line_colors.length() - 0);
        mShader = new LinearGradient(0, 0, getMeasuredWidth(), 0, new int[]{Color.parseColor("#00" + line_colors), line_color, Color.parseColor("#00" + line_colors),}, null,
                Shader.TileMode.CLAMP);
        paint.setShader(mShader);
        canvas.drawLine(0, 0, getMeasuredWidth(), 0, paint);
    }


}
